package com.wd.tw.controller;

import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.serotonin.modbus4j.exception.ModbusTransportException;
import com.wd.common.core.domain.HttpResponse;
import com.wd.tw.config.AppConfig;
import com.wd.tw.config.ModbusUtil;
import com.wd.tw.domain.aie.EventResponse;
import com.wd.tw.server.WebSocketEndpoint;
import com.wd.tw.service.*;
import lombok.extern.slf4j.Slf4j;
import netscape.javascript.JSObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import static com.wd.tw.constants.EleConstant.ELE_CROWD_NUM;

/**
 * @className: CusController
 * @description: TODO 类描述
 * @author: liumingkun
 * @date: 2024/11/17
 **/
@RestController
@Slf4j
public class CusController {

    private final static Logger logger = LoggerFactory.getLogger(CusController.class);

    @Resource
    EventService eventService;

    @Resource
    AppConfig appConfig;

    @Resource
    ModbusService modbusService;

    @Resource
    BooleanCountService countService;

    @Resource
    ChannelMapService channelMapService;

    @Resource
    TokenService tokenService;


    @RequestMapping("/aie/socket")
    public HttpResponse testB() {
        WebSocketEndpoint.sendToClient("socket test!");
        return HttpResponse.success();
    }

    @RequestMapping("/app/config")
    public HttpResponse getAppConfig(){
        return HttpResponse.successData(appConfig.getSignalBit());
    }



    @RequestMapping("/set/pCount")
    public HttpResponse setPCount(int channel,int count) {
        ELE_CROWD_NUM.put(channelMapService.getStId(channel), count);
        return HttpResponse.success();
    }

    @RequestMapping("/aie/token")
    public HttpResponse getToken() {

        return HttpResponse.success(tokenService.getToken());
    }

}
